import 'package:flutter/material.dart';
import 'package:flutter_app_action/pages/camera_page.dart';
import 'package:flutter_app_action/pages/home_page.dart';
import 'package:flutter_app_action/pages/search_page.dart';
import 'package:flutter_app_action/pages/user_page.dart';
import 'package:flutter_app_action/each_view.dart';

class NavigatorsBar extends StatefulWidget {
  @override
  _NavigatorsBarState createState() => _NavigatorsBarState();
}

class _NavigatorsBarState extends State<NavigatorsBar> {
  final __defaultColor = Colors.black;
  final __activeColor = Colors.blue;
  int _currentIndex = 0;


  List<Widget> _eachView;

//  final _pageController=PageController(
//    initialPage: 0
//  );

  @override
  void initState() {
    _eachView = List();
//    listWidget
//      ..add(HomePage())
//      ..add(CameraPage())
//      ..add(SearchPage())
//      ..add(UserPage());
    _eachView
      ..add(EachView("home"))
      ..add(EachView("camera"))
      ..add(EachView("search"))
      ..add(EachView("user"));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
//      body: PageView(
//           controller: _pageController,
//           children: <Widget>[
//              HomePage(),
//              CameraPage(),
//              SearchPage(),
//              UserPage(),
//           ],
//         ),
      body: _eachView[_currentIndex],
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.of(context)
              .push(MaterialPageRoute(builder: (BuildContext context) {
            return EachView("user");
          }));
        },
        tooltip: 'add',
        elevation: 0.0,
//        backgroundColor: Colors.white,
        child: Icon(
          Icons.camera_alt,
//          color: Colors.blue,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
//      bottomNavigationBar: BottomNavigationBar(
//        currentIndex: _currentIndex,
//        type: BottomNavigationBarType.fixed,
//        onTap: (index) {
//          setState(() {
//            _currentIndex = index;
////            _pageController.jumpToPage(index);
//          });
//        },
//        items: [
//          BottomNavigationBarItem(
//              title: Text(
//                "Home",
//                style: TextStyle(
//                    color: _currentIndex == 0 ? __activeColor : __defaultColor),
//              ),
//              icon: Icon(
//                Icons.home,
//                color: __defaultColor,
//              ),
//              activeIcon: Icon(
//                Icons.home,
//                color: __activeColor,
//              )),
//          BottomNavigationBarItem(
//            title: Text(
//              "Camera",
//              style: TextStyle(
//                  color: _currentIndex != 1 ? __defaultColor : __activeColor),
//            ),
//            icon: Icon(
//              Icons.camera_alt,
//              color: __defaultColor,
//            ),
//            activeIcon: Icon(
//              Icons.camera_alt,
//              color: __activeColor,
//            ),
//          ),
//          BottomNavigationBarItem(
//            title: Text(
//              "search",
//              style: TextStyle(
//                  color: _currentIndex != 2 ? __defaultColor : __activeColor),
//            ),
//            icon: Icon(
//              Icons.search,
//              color: __defaultColor,
//            ),
//            activeIcon: Icon(
//              Icons.search,
//              color: __activeColor,
//            ),
//          ),
//          BottomNavigationBarItem(
//            title: Text(
//              "User",
//              style: TextStyle(
//                  color: _currentIndex != 3 ? __defaultColor : __activeColor),
//            ),
//            icon: Icon(
//              Icons.account_circle,
//              color: __defaultColor,
//            ),
//            activeIcon: Icon(
//              Icons.account_circle,
//              color: __activeColor,
//            ),
//          ),
//        ],
//      ),

      bottomNavigationBar: BottomAppBar(
        color: Colors.white,
        shape: CircularNotchedRectangle(),
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.home),
              tooltip: "Home",
              color: _currentIndex==0?__activeColor:__defaultColor,
              onPressed: () {
                setState(() {
                  _currentIndex = 0;
                });
              },
            ),
            IconButton(
              icon: Icon(Icons.camera_alt),
              color: _currentIndex==1?__activeColor:__defaultColor,
              onPressed: () {
                setState(() {
                  _currentIndex = 1;
                });
              },
            ),
            IconButton(
              icon: Icon(Icons.search),
              color: _currentIndex==2?__activeColor:__defaultColor,
              onPressed: () {
                setState(() {
                  _currentIndex = 2;
                });
              },
            ),
            IconButton(
              icon: Icon(Icons.account_circle),
              color: _currentIndex==3?__activeColor:__defaultColor,
              onPressed: () {
                setState(() {
                  _currentIndex = 3;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
